import { DataTableInst } from 'naive-ui'
import { Ref } from 'vue'

type Props = {
  pageIndex: any
  pageSize: any
  dataTableInst: Ref<DataTableInst | null>
}

/**
 * 当发生页数、每页大小发生变化时，表格滚动到最上方
 * @param param
 */
export function useTableScrollToTop({
  pageIndex,
  pageSize,
  dataTableInst
}: Props) {
  watch(pageIndex, () => {
    dataTableInst.value?.scrollTo({
      top: 0,
      behavior: 'smooth'
    })
  })
  watch(pageSize, () => {
    dataTableInst.value?.scrollTo({
      top: 0,
      behavior: 'smooth'
    })
  })
}
